package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/3/11 9:05
 * Version:1.0-SNAPSHOT
 */
@Controller
@RequestMapping("/url")
public class URLController {

    @RequestMapping("/f1/*")
    public void f1(){
        System.out.println("URLController.f1");
    }

    @RequestMapping("/f2/**")
    public void f2(){
        System.out.println("URLController.f2");
    }

    @RequestMapping("/f3/?")
    public void f3(){
        System.out.println("URLController.f3");
    }

    @RequestMapping("/f4/a?")
    public void f4(){
        System.out.println("URLController.f4");
    }

    @RequestMapping("/f5/{name}")
    public void f5(@PathVariable("name") String name){
        System.out.println("name:"+name);
    }

    @RequestMapping("/f6/{name}")
    public void f6(@PathVariable String name){
        System.out.println("name:"+name);
    }

    @RequestMapping("/f7/{password}/{username}")
    public void f7(@PathVariable String username,@PathVariable String password){
        System.out.println("username:"+username+",password:"+password);
    }

    @RequestMapping("/f8/{id}")
    public void f8(@PathVariable Integer id){
        System.out.println("id:"+id);
    }

    // 限制当前输入的地址的值(占位符id部分的值)必须为数字
    // 如果输入的不是一个数字,不让访问
    // 1或多个数字
    @RequestMapping("/f9/{id:\\d+}")
    public void f9(@PathVariable Integer id){
        System.out.println("id:"+id);
    }

    @RequestMapping({"/f10","/fn10","/test10"})
    public void f10(){
        System.out.println("URLController.f10");
    }

    @ResponseBody
    @RequestMapping(value = "/f11",method = RequestMethod.GET)
    public String f11(){
        return "<h1>Hello GET</h1>";
    }

    @ResponseBody
    @RequestMapping(value = "/f12",method = RequestMethod.POST)
    public String f12(){
        return "<h1>Hello POST</h1>";
    }

    // @GetMapping("/f13") == @RequestMapping(value = "/f13",method = RequestMethod.GET)
    @ResponseBody
    @GetMapping("/f13")
    public String f13(){
        return "<h1>Hello GET</h1>";
    }

    @ResponseBody
    @PutMapping("/f14")
    public String f14(){
        return "<h1>Hello PUT</h1>";
    }

    @RequestMapping(value = "/f15",params = "username")
    public void f15(){
        System.out.println("URLController.f15");
    }

    @RequestMapping(value = "/f16",params = "username=admin")
    public void f16(){
        System.out.println("URLController.f15");
    }

    @RequestMapping(value = "/f17",params = "username!=admin")
    public void f17(){
        System.out.println("URLController.f15");
    }


}
